package com.vinaprime.primeschedule.presentation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewAdapter extends BaseAdapter {
	 
	String[] textArray;
    Context context;
    Integer[] images;
 
    public GridViewAdapter(String[] _textArray,Integer[] _images ,Context _context) {
        textArray = _textArray;
        images = _images;
        context=_context;
    }
 
    @Override
    public int getCount() {
 
        return textArray.length;
    }
 
    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }
 
    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return 0;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
 
        // create a new LayoutInflater
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
        View gridView;
        gridView = null;
        convertView = null;// avoids recycling of grid view
        if (convertView == null) {
 
            gridView = new View(context);
            // inflating grid view item
            gridView = inflater.inflate(R.layout.activity_main_menu, null);
 
            
            // set value into textview
            TextView textView = (TextView) gridView
                    .findViewById(R.id.txtMenuMain);
            textView.setText(textArray[position].toString());
                        // set value into ImageView
            ImageView imgView = (ImageView)gridView.findViewById(R.id.imageMenuMain);
            imgView.setImageResource(images[position]);
 
        }
 
        return gridView;
    }
 
}